package com.tllq.zhongkang.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tllq.zhongkang.entity.UpdateCard;
import com.tllq.zhongkang.mapper.UpdateCardMapper;
import com.tllq.zhongkang.service.UpdateCardService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j
public class UpdateCardServiceImpl extends ServiceImpl<UpdateCardMapper, UpdateCard> implements UpdateCardService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    UpdateCardMapper updateCardMapper;

    @Override
    public Integer findById(Integer id) {
        return updateCardMapper.findById(id);
    }

    @Override
    public void update(UpdateCard updateCard) {
        logger.info("传入数据" + updateCard);
        try {
            //更新资料
            updateCardMapper.update(updateCard);
            logger.info("更新资料成功，参数：{}",updateCard);
        } catch (Exception e) {
            RuntimeException runtimeException = new RuntimeException("更新资料异常 参数："+updateCard+ "错误"+ e.getMessage());
            logger.error(runtimeException.getMessage());
            throw runtimeException;
        }
        try {
            //启用
            updateCardMapper.updatestart(updateCard);
            logger.info("启用成功,参数：{}",updateCard);
        } catch (Exception e) {
            RuntimeException runtimeException = new RuntimeException(e.getMessage());
            logger.error("启用失败参数：" +updateCard+"错误"+runtimeException.getMessage());
            throw runtimeException;
        }

    }

    @Override
    public Integer findBymobile(String mobile) {
        return updateCardMapper.findBymobile(mobile);
    }

    @Override
    public Integer findStore(Integer placepiontid) {
        Integer store = null;
        try {
            store = updateCardMapper.findStore(placepiontid);
            return store;
        } catch (Exception e) {
            return 0;
        }

    }


}
